<template>
    <div class="weaponInfo">
        <div class="loading" v-if="pageStat">
            <Loading></Loading>
        </div>
        <div class="content" v-if="!pageStat">
            <div class="header">
                <div class="headerImg">
                    <van-image width="100%" height="10rem" fit="cover" :src="weaponInfo.weaponImg" />
                    <img :src="weaponInfo.weaponIcon" class="weaponIcon">
                    <img src="../static/image/left.png" alt="" class="back" @click="back">

                </div>
                <div class="weaponDetails">
                    <span class="weaponName">{{weaponInfo.weaponName}}</span>
                    <div class="weaponSubtitle">
                        <span>{{weaponInfo.level}} </span>
                        <span>{{weaponInfo.type}} </span>
                        <div class="attribute">
                            <img :src="weaponInfo.damage_type_icon" alt="">
                            <span>{{weaponInfo.damage_type}}</span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="weaponExtras">
                <span>{{weaponInfo.header__description}}</span>
                <span v-if="weaponInfo.header__lore!=null" style="color:#2B9FEA;margin-left:5px;font-weight:bold"
                    @click="loadLore">Read
                    Lore</span>
                <transition name="fade">
                    <div v-if="loreStat" class="lore">
                        <p v-for="loreItme in lore" :key="loreItme">{{loreItme}}</p>

                    </div>
                </transition>

            </div>
            <div class="match">
                <div class="filed" v-if="weaponInfo.matchName==null">
                    过去30天使用人数过少
                </div>
                <p class="matchName">{{weaponInfo.matchName}}</p>
                <div class="insights">
                    <div class="insightsCard" v-for="insights in weaponInfo.insights" :key="insights[0]">
                        <span>{{insights[0]}}</span>
                        <span>{{insights[1]}}</span>
                        <span style="font-size:13px">{{insights[2]}}</span>
                        <van-progress :percentage="100" stroke-width="14" pivot-text="" class="progress"
                            v-if="insights[0]=='Usage'" />
                        <van-progress :percentage="100" stroke-width="14" pivot-text="" class="progress" color="#ee0a24"
                            v-if="insights[0]=='Kills'" />
                        <van-progress :percentage="100" stroke-width="14" pivot-text="" class="progress" color="#fdae61"
                            v-if="insights[0]=='Headshots'" />

                    </div>
                </div>
            </div>
            <div class="statList">
                <p class="statListTitle">Item Statistics</p>
                <p class="statListDescription">Selecting weapon perks and mods can alter the stats shown
                    below.</p>
                <ul class="statGroup">
                    <li v-for="statList in weaponInfo.statList" :key="statList.stat__name">
                        <div class="statItem">
                            <span class="statName">{{statList.stat__name}}</span>
                            <van-progress :percentage="statList.style" stroke-width="18" pivot-text=""
                                class="statProgress" color="#ffffff" track-color="#999999" />
                            <span class="statValue">{{statList.stat__value}}</span>
                        </div>
                    </li>
                </ul>
            </div>
        </div>

    </div>
</template>

<script>
    import axios from 'axios'
    import Loading from '@/components/loading/Loading.vue'

    export default {
        data() {
            return {
                pageStat: true,
                loreStat: false,
                lore: [],
                weaponInfo: ''
            }
        },
        components: {
            Loading
        },
        created() {
            this.getWeaponInfo()
        },
        methods: {
            getWeaponInfo() {
                console.log(this.$route.params.id)
                var id = this.$route.params.id
                axios.get("/api/getWeaponInfo", {
                        params: {
                            id: id
                        }
                    })
                    .then(res => {
                        this.weaponInfo = res.data
                        if (res.data.header__lore != null) {
                            this.lore = res.data.header__lore.split("\"");

                        } else {
                            this.lore = res.data.header__lore;
                        }
                        this.$nextTick(() => {
                            this.pageStat = false
                        })
                    })
                    .catch(err => {
                        console.error(err);
                    })
            },
            loadLore() {
                console.log(this.loreStat)
                this.loreStat = !this.loreStat
                console.log(this.loreStat)

            },
            back() {
                this.$router.go(-1)
            }
        }
    }
</script>

<style scoped>
    .loading {
        height: 812px;
        overflow: hidden;
    }

    .weaponInfo {
        background: #1F1F1F;
        height: 100%;
        color: white;
    }

    .headerImg {
        position: relative;
    }

    .back {
        position: absolute;
        top: 5px;
        left: 5px;
        width: 30px;
        height: 30px;
    }

    .weaponIcon {
        position: absolute;
        bottom: -40px;
        left: 20px;
        width: 75px;
        height: 75px;
        border-radius: 10px;
    }

    .weaponDetails {
        margin-top: 50px;
        margin-left: 20px;
    }

    .weaponName {
        font-size: 35px;
        font-weight: bold;
        font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif;
    }

    .weaponSubtitle {
        display: flex;
        font-size: 15px;
        margin-top: 5px;
    }

    .attribute {
        display: flex;
        align-items: center;
    }

    .attribute>img {
        width: 13px;
        height: 13px;
    }

    .weaponSubtitle>:not(:last-child):after {
        content: " | ";
        color: var(--text-color-muted);
        opacity: .5;
    }

    .weaponExtras {
        background: #3f3d3d;
        margin-top: 10px;
        padding: 20px 20px;
        font-size: 15px;
        font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
    }

    .lore {
        border-left: 4px white solid;
        padding: 0 15px;
    }

    .match {
        padding-bottom: 20px;
        border-bottom: 1px solid white;

    }

    .matchName {
        font-size: 30px;
        margin: 0;
        padding: 15px 20px;
        font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
        border-bottom: 1px solid white;

    }

    .insightsCard {
        margin: 10px 20px;
        overflow: hidden;
    }

    .insightsCard>span {
        font-size: 18px;
        margin: 0 3px;
        font-weight: bold;
        font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    }

    .progress {
        margin-top: 5px;
    }

    .statListTitle {
        font-size: 30px;
        margin: 0;
        padding: 15px 20px;
        font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
    }

    .statListDescription {
        margin-top: -20px;
        padding: 10px 20px;
        border-bottom: 1px solid white;

    }

    .statGroup {
        margin: 0 20px;
        padding-bottom: 20px;
    }

    .statItem {
        display: flex;
        justify-content: flex-end;
        margin: 10px 0;
        font-family: 'Trebuchet MS', 'Lucida Sans Unicode', 'Lucida Grande', 'Lucida Sans', Arial, sans-serif;
    }

    .statProgress {
        width: 150px;
    }

    .statName {
        margin-right: 10px;
    }

    .statValue {
        width: 32px;
        margin-left: 10px;
        margin-right: 15px;
    }

    .fade-enter-active,
    .fade-leave-active {
        transition: opacity .25s;
    }

    .fade-enter,
    .fade-leave-to {
        opacity: 0;
    }

    .filed {
        font-size: 30px;
        text-align: center;
    }
</style>